<?php

class Ext_Buddy
{
    protected $_buddyUserId;
    
    protected $_messager;
    const MESSAGE_NOT_LOGIN                              = 'notLogin';
    const MESSAGE_BUDDY_SELF_FORBIDDEN                   = 'buddySelfForbidden';
    const MESSAGE_IS_ALREADY_YOUR_BUDDY                  = 'isAlreadyYourBuddy';
    const MESSAGE_IS_NOT_YOUR_BUDDY_YET                  = 'isNotYourBuddyYet';
    protected $_messageTemplates = array(
        self::MESSAGE_NOT_LOGIN                          => "Please login.",
        self::MESSAGE_BUDDY_SELF_FORBIDDEN               => "You can't buddy your self.",
        self::MESSAGE_IS_ALREADY_YOUR_BUDDY              => "Is already your buddy.",
        self::MESSAGE_IS_NOT_YOUR_BUDDY_YET              => "Is not your buddy yet.",
    );
    
    public function __construct($buddyUserId)
    {
        $this->_messager = new Ext_Messager($this->_messageTemplates);
        
        $this->_buddyUserId = $buddyUserId;
    }
    
    public function save($buddy)
    {
        $result = array(
            'code'      => Ext_Publish_Attachment_Add_Result::FAILURE,
            'messages'  => array(),
        );
        
        $auth = Ext_Auth::getInstance();
        $userId = $auth->getIdentity();
        
        if(!$userId){
            
        }
    }
    
    public function validate($isBuddy)
    {
        $this->_validater = new Ext_Buddy_Validate($this->_loginUserId, $this->_buddyUserId);
        $this->_validater->validate($isBuddy);
    }
    
    public function getValidater()
    {
        return $this->_validater;
    }
    
    public function remove()
    {
        $_appModelDbTableBuddy = App_Model_DbTable_Buddy::getInstance();
        $buddyRow = $_appModelDbTableBuddy->getRowByUserIdBuddyUserId($this->_loginUserId, $this->_buddyUserId);
        if(isset($buddyRow['id']))
        {
            $_appModelDbTableBuddy->del($buddyRow['id']);
        }
    }
    
    public function add()
    {
        $_appModelDbTableBuddy = App_Model_DbTable_Buddy::getInstance();
        
        $inputArray = array(
			'userId' 			=> $this->_loginUserId,
			'buddyUserId' 		=> $this->_buddyUserId,
		);
		$_appModelDbTableBuddy->add($inputArray);
    }
}
